// ChooseReportFieldDlg.cpp : implementation file
//

#include "stdafx.h"
#include "kwclientcore.h"
#include "ChooseReportFieldDlg.h"

#include "CommonLib\Structure.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CChooseReportFieldDlg dialog


CChooseReportFieldDlg::CChooseReportFieldDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CChooseReportFieldDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CChooseReportFieldDlg)
	//}}AFX_DATA_INIT
}


void CChooseReportFieldDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CChooseReportFieldDlg)
	DDX_Control(pDX, IDC_CHOOSEREPORTFIELD_LIST, m_listbox);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CChooseReportFieldDlg, CDialog)
	//{{AFX_MSG_MAP(CChooseReportFieldDlg)
	ON_WM_VKEYTOITEM()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChooseReportFieldDlg message handlers

BOOL CChooseReportFieldDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
  for (int i = 0;i < ReportField::NumOfFields;i++) 
  {
    m_listbox.AddString(ReportField::GetFieldName(i));
  }
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CChooseReportFieldDlg::OnOK() 
{
	// TODO: Add extra validation here
	m_FieldIds.clear();
  CString str;
  for (int i = 0;i < ReportField::NumOfFields;i++) 
  {
    if (m_listbox.GetSel(i) > 0) 
    {
      m_FieldIds.push_back(i);
    }
  }

	CDialog::OnOK();
}

int CChooseReportFieldDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) 
{
	// TODO: Add your message handler code here and/or call default
  if (pListBox == &m_listbox)
  {
    if (nKey == 'A' && HIBYTE(GetKeyState(VK_CONTROL))) 
    {
      for (int i = 0;i < pListBox->GetCount();i++) pListBox->SetSel(i);
      return -2;
    }
    if (nKey == VK_BACK) 
    {
      for (int i = 0;i < pListBox->GetCount();i++) pListBox->SetSel(i, FALSE);
      return -2;
    }
    return -1;
  }
	
	return CDialog::OnVKeyToItem(nKey, pListBox, nIndex);
}
